if(typeof RD_ORDER=="undefined"||!RD_ORDER) var RD_ORDER={};

RD_ORDER.items = {
	a : [['降序','0'],['升序','1'],['取消','2']],
	b : [['降序','0'],['升序','1'],['取消','2']],//[['从高到低','0'],['从低到高','1'],['取消','2']]
	c : [['降序','0'],['升序','1'],['取消','2']],//[['从新到旧','0'],['从旧到新','1'],['取消','2']]
	d : [['降序','0'],['升序','1'],['取消','2']],//[['从近到远','0'],['从远到近','1'],['取消','2']]
	e : [['降序','0'],['升序','1'],['取消','2']],//[['从大到小','0'],['从小到大','1'],['取消','2']]
	f : [['升序','1'],['降序','0'],['取消','2']],//[['按拼音从a-z','1'],['按拼音从z-a','0'],['取消','2']]
	g : [['降序','0'],['升序','1'],['取消','2']],//[['从多到少','0'],['从少到多','1'],['取消','2']]
	h : [['降序','0'],['升序','1'],['取消','2']],//[['从早到晚','0'],['从晚到早','1'],['取消','2']]
	i : [['降序','0'],['升序','1'],['取消','2']]//[['先女后男','0'],['先男后女','1'],['取消','2']]
}

RD_ORDER.Dom = {
	getCurrentStyle : function(e,s){//read only
    	var retVal;
    	if(e.currentStyle) retVal=e.currentStyle[s];//IE
		else if(document.defaultView&&document.defaultView.getComputedStyle) retVal=document.defaultView.getComputedStyle(e,null).getPropertyValue(this.dashify(s));//Mozilla
		else retVal=null;//Safari
    	return retVal;
	},
	dashify : function(str){
    	return str.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase();
	},
	getLocalOffset : function(offset,direction){//direction: Top Left
		var y=offset['offset'+direction];
    	var div;
    	try{div=offset.offsetParent;}
		catch(ex){return y;}
    	while(div&&RD_ORDER.Dom.getCurrentStyle(div,'position')=='static'){
        	y+=div['offset'+direction];
        	try{div=div.offsetParent;}
			catch(ex){return y;}
    	}
    	return y;
	},
	myAttachEvent : function(d,e,f){
		try {
			if(d.attachEvent) d.attachEvent("on"+e,f);
			else if(d.addEventListener) d.addEventListener(e,f,false);
			else{
				var oldF = eval('d.on'+e);
				if(typeof oldF!='function') eval('d.on'+e+'=f');
				else eval('d.on'+e)=function(){oldF();f();}
			}
		}
		catch (error){}
	}
}

RD_ORDER.blankFn = function(){
	return;
}

RD_ORDER.fnInit = function(){
	if(!RD_ORDER.dhtml) RD_ORDER.dhtml = (function(){
												   var myDiv = document.createElement('div');
												   myDiv.style.visibility = 'hidden';
												   myDiv.style.position = 'absolute';
												   myDiv.style.top = '-100px';
												   myDiv.style.left = '-100px';
												   myDiv.style.zIndex = '99';
												   myDiv.className = 'popupDiv_mini';
												   myDiv.id = 'RD_order_div';
												   document.body.appendChild(myDiv);
												   myDiv.onmouseover = function(){RD_ORDER.stopTimeCon();};
												   myDiv.onmouseout = function(){RD_ORDER.startTimeCon();};
												   return myDiv;
												   })()
	if(RD_ORDER.dhtml){
		if(RD_ORDER.dhtml.currentStyle && navigator.userAgent.indexOf("MSIE 7") == -1){//ie6
			if(!RD_ORDER.shim){
					RD_ORDER.shim = document.createElement('iframe');
					RD_ORDER.shim.src = 'javascript:""';
            		RD_ORDER.shim.frameBorder = '0';
            		RD_ORDER.shim.scrolling = 'no';
            		RD_ORDER.shim.className = 'iframeShim';
            		RD_ORDER.shim.style.zIndex = RD_ORDER.dhtml.currentStyle.zIndex - 1;
					RD_ORDER.shim.style.position = 'absolute';
					RD_ORDER.shim.style.visibility = 'hidden';
					RD_ORDER.shim.style.width = RD_ORDER.Dom.getCurrentStyle(RD_ORDER.dhtml,'width');
					RD_ORDER.shim.style.height = RD_ORDER.Dom.getCurrentStyle(RD_ORDER.dhtml,'height');
					RD_ORDER.shim.style.left = RD_ORDER.Dom.getLocalOffset(RD_ORDER.dhtml,'Left');
					RD_ORDER.shim.style.top = RD_ORDER.Dom.getLocalOffset(RD_ORDER.dhtml,'Top');
					RD_ORDER.dhtml.parentNode.appendChild(RD_ORDER.shim);
			}
		}
		if(!RD_ORDER.allHTML || !RD_ORDER.allHTML instanceof Array) RD_ORDER.allHTML = [];
		if(!RD_ORDER.alldHTML || !RD_ORDER.alldHTML instanceof Array) RD_ORDER.alldHTML = [];
		var e=/<[^>]+\srdmodule=[\'\"]?([\w|]+)[^>]+/g;
		var g=/id=[\'\"]?([\w\-]+)/i;
		var i,j;
		window.document.body.innerHTML.replace(e,function(a,b){if(b=="order"&&(i=a.match(g))&&(j=document.getElementById(i[1]))){
																	RD_ORDER.allHTML.push(j);
																	RD_ORDER.alldHTML[j.id] = new RD_ORDER.orderFactory(j);
																}
																return''
												});
	}
}

RD_ORDER.timeControlOn=false;
RD_ORDER.startTimeCon = function(){
	if(this.timeControlOn == false){
		this.timeControl = setTimeout('RD_ORDER.hideOrderDiv()',100);
		this.timeControlOn = true;
	}
};
RD_ORDER.stopTimeCon = function(){
	if(this.timeControlOn){
		clearTimeout(this.timeControl);
		this.timeControl = null;
		this.timeControlOn = false;
	}
};
RD_ORDER.hideOrderDiv = function(){
	this.dhtml.style.visibility = 'hidden';
	if(this.shim) this.shim.style.visibility = 'hidden';
};

RD_ORDER.orderFactory = function(h){
	var s = this;
	s.html = h;
	s.type = s.html.getAttribute('ordertype')||'a';
	s.itemInfo = RD_ORDER.items[s.type]||RD_ORDER.items['a'];
	s.aspFn = s.html.getAttribute('orderfn')||'RD_ORDER.blankFn';
	s.aspFn_argu = s.html.getAttribute('ordername')||null;
	s.flagCancel = s.html.getAttribute('ordercancel')||'yes';//no : hidden   yes : visibile
	s.orderVal = s.html.getAttribute('ordervalue')||'';
	RD_ORDER.Dom.myAttachEvent(s.html,'mouseover',function(e){s.fnMouseOver(e);});
	RD_ORDER.Dom.myAttachEvent(s.html,'mouseout',function(e){s.fnMouseOut(e);});
	//s.html.onmouseover = function(e){s.fnMouseOut(e);};
	//s.html.onmouseout = function(e){s.fnMouseOut(e);};
}
RD_ORDER.orderFactory.prototype = {
	fnMouseOver : function(e){
		var s = this;
		var myEve = e?e:window.event;
		if(RD_ORDER.dhtml){
			if(RD_ORDER.dhtml.style.visibility=='visible') RD_ORDER.dhtml.style.visibility = 'hidden';
			RD_ORDER.dhtml.innerHTML = s.genDivHTML();
			
			/*var tempP = s.html;
			var fixP = null,fixScrollX = 0,fixScrollY = 0;
			while(tempP.className!='tableConXL'){
				if(tempP.parentNode&&tempP.parentNode.tagName.toLowerCase()!='html') tempP = tempP.parentNode;
				else break;
			}
			if(tempP.className=='tableConXL') fixP = tempP;
			if(fixP!=null){
				fixScrollX = fixP.scrollLeft;
				fixScrollY = fixP.scrollTop;
			}*/
			var tempP = s.html;
			var fixP = null,fixScrollX = 0,fixScrollY = 0;
			while(RD_ORDER.Dom.getCurrentStyle(tempP,'overflowX')!='auto'&&RD_ORDER.Dom.getCurrentStyle(tempP,'overflowX')!='scroll'&&RD_ORDER.Dom.getCurrentStyle(tempP,'overflowY')!='auto'&&RD_ORDER.Dom.getCurrentStyle(tempP,'overflowY')!='scroll'){
				if(tempP.parentNode&&tempP.parentNode.tagName.toLowerCase()!='html') tempP = tempP.parentNode;
				else break;
			}
			if(tempP.tagName.toLowerCase()!='html') fixP = tempP;
			if(fixP!=null){
				fixScrollX = fixP.scrollLeft;
				fixScrollY = fixP.scrollTop;
			}
			
			s.divX = RD_ORDER.Dom.getLocalOffset(s.html,'Left')-fixScrollX;
			s.divY = RD_ORDER.Dom.getLocalOffset(s.html,'Top')+14-fixScrollY;
			RD_ORDER.dhtml.style.left = s.divX + 'px';
			RD_ORDER.dhtml.style.top = s.divY + 'px';
			RD_ORDER.dhtml.style.visibility = 'visible';
			if(RD_ORDER.shim){
				RD_ORDER.shim.style.left = RD_ORDER.dhtml.currentStyle.left;
				RD_ORDER.shim.style.top = RD_ORDER.dhtml.currentStyle.top;
				RD_ORDER.shim.style.width = RD_ORDER.dhtml.offsetWidth;
				RD_ORDER.shim.style.height = RD_ORDER.dhtml.offsetHeight;
				RD_ORDER.shim.style.visibility = 'visible';
			}
			RD_ORDER.stopTimeCon();
		}
	},
	fnMouseOut : function(e){
		var s = this;
		var myEve = e?e:window.event;
		if(RD_ORDER.dhtml) RD_ORDER.startTimeCon();
	},
	closeOrderDiv : function(){
		hideCurrentPopup();
	},
	genDivHTML : function(){
		var s = this;
		var strHTML = '<div class="title">排序方式</div><div class="content"><ul>';
		for(var i=0;s.itemInfo[i];i++){
			if(s.itemInfo[i][1]==s.orderVal || (s.itemInfo[i][1]==2&&s.flagCancel=='no')) continue;
			strHTML += '<li class="listorderItem'+s.itemInfo[i][1]+'"><a href="#" onclick="'+s.aspFn+'(\''+s.aspFn_argu+'\',\''+s.itemInfo[i][1]+'\');return false;" onfocus="this.blur()">'+s.itemInfo[i][0]+'</a></li>';
		}
		strHTML += '</ul></div>';
		return strHTML;
	}
}

RD_ORDER.Dom.myAttachEvent(window,'load',RD_ORDER.fnInit);